import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

/**
 * Created with IntelliJ IDEA.
 * User: Virus1908
 * Date: 17.11.13
 * Time: 21:22
 */
public class TextElement {
    private JTextArea name;
    private JLabel type;
    private JTextArea accords;
    private JTextArea text;
    private JPanel root;

    private String elementType;

    public void setElementType(String typeString) {
        elementType = typeString;
        type.setText("Тип елементу - " + typeString);
//        root.setSize(root.getWidth(), 250);
    }

    public Element getXml(Document doc) throws ParserConfigurationException {
        Element root = doc.createElement(elementType);
        String nameString = name.getText();
        String accordsString = accords.getText();
        String textString = text.getText();
        if (nameString != null && !nameString.isEmpty()) {
            Element name = doc.createElement("title");
            name.appendChild(doc.createTextNode(nameString));
            root.appendChild(name);
        }
        if (accordsString != null && !accordsString.isEmpty()) {
            Element accords = doc.createElement("accords");
            accords.appendChild(doc.createTextNode(accordsString));
            root.appendChild(accords);
        }
        if (textString != null && !textString.isEmpty()) {
            Element text = doc.createElement("text");
            text.appendChild(doc.createTextNode(textString));
            root.appendChild(text);
        }
        return root;
    }

    public JPanel getRoot() {
        return root;
    }

    private void createUIComponents() {
        // TODO: place custom component creation code here
    }
}
